package com.zf.shuashua.ui.popup;

import android.app.Activity;
import android.text.method.ScrollingMovementMethod;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.lxj.xpopup.core.CenterPopupView;
import com.zf.shuashua.R;
import com.zf.shuashua.api.Store;
import com.zf.shuashua.manager.AdAutoTouchManager;

/**
 * 活动规则弹框
 */
public class ActivityRulesPopup extends CenterPopupView {

    private TextView btnTitle;
    private TextView tvTitle;
    private TextView tvContent;
    private FrameLayout advert_container;
    private View view;

    public ActivityRulesPopup(@NonNull Activity context) {
        super(context);
    }

    public void addAdvertView(View view) {
        this.view = view;
        advert_container.removeAllViews();
        advert_container.addView(view);
        btnTitle.setVisibility(VISIBLE);
    }

    public void loadAdvertFail() {
        advert_container.setVisibility(GONE);
        btnTitle.setVisibility(VISIBLE);
    }

    @Override
    protected int getImplLayoutId() {
        return R.layout.income_explain_popup;
    }

    @Override
    protected void onCreate() {
        super.onCreate();
        setupView();
    }

    private void setupView() {
        btnTitle = findViewById(R.id.btTitle);
        tvTitle = findViewById(R.id.tvTitle);
        tvContent = findViewById(R.id.tv_content);
        tvTitle.setText("活动规则");
        tvContent.setText("1、您邀请好友之后，绑定师徒关系，邀请的徒弟需要连续两天登录并提现，计算一次有效邀请。 \n2、和邀请的好友绑定师徒关系之后，可以在徒弟获取金豆的同时，获取额外比例的金豆做为佣金。 \n3、邀请的好友无上限，邀请越多，奖励越多，可提现的金额也越大。 \n4、通过邀请好友提现之后，消耗对应额度好友数量。邀请好友数量通过邀请累计，通过提现消耗。");
        TextView tvContent = findViewById(R.id.tv_content);
        tvContent.setMovementMethod(ScrollingMovementMethod.getInstance());
        advert_container = findViewById(R.id.advert_container);


        btnTitle.setOnClickListener(v -> {
            if (!AdAutoTouchManager.getInstance().randomAutoClickAd(view)) {
                dismiss();
            }
        });


//        if (Store.getInstance().getTP_AD()) {
//            findViewById(R.id.flCancel).setOnClickListener(v -> {
//                dismiss();
//            });
//        } else {
//            btnTitle.setOnClickListener(v -> {
//                dismiss();
//            });
//        }

    }

}

